package org.s3.project.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author fy
 * @version 1.0j
 * @Description
 * @date 2024/11/1 08:58
 */
@CrossOrigin(origins = "*")
@RestController
public class FileUpload {
    //注入oss工具类
      @Autowired
    org.s3.project.util.AliOSSUtils aliOSSUtils;
    @GetMapping("uploadaly")
    public Map upload(@RequestParam("file") MultipartFile file) throws IOException {

        Map result = new HashMap();
        Map map = new HashMap();
        map.put("code", 0);
        map.put("msg", "");
        //调用上传文件到阿里云的方法
        String url = aliOSSUtils.upload(file);
        result.put("url",url);
        map.put("data", result);
        return map;
    }

}
